home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 1002 b | 52 lines | [TEXT/CWIE] |
- // PlainMenuItem.h
-
- #ifndef PlainMenuItem_h
- #define PlainMenuItem_h
-
- #ifndef SingleMenuItem_h
- #include "SingleMenuItem.h"
- #endif
- #ifndef Commander_h
- #include "Commander.h"
- #endif
-
- template < class TheProtocol >
- class PlainMenuItem: public SingleMenuItem
- {
- typedef TheProtocol Protocol;
- typedef const Protocol ConstProtocol;
-
- private:
- bool (ConstProtocol::*canDo)();
- void (Protocol::*doIt)();
-
- public:
- PlainMenuItem( Menu& menu,
- void (Protocol::*toDo)(),
- bool (ConstProtocol::*canDoIt)() = 0 )
- : SingleMenuItem( menu ),
- canDo( canDoIt ),
- doIt( toDo )
- {}
-
- virtual void Prepare()
- {
- if ( Commander<Protocol>::Null() )
- Disable();
- else
- if ( canDo == 0 )
- Enable();
- else
- SetEnabled( ((*Commander<Protocol>()).*canDo)() );
- }
-
- virtual void Choose()
- {
- Assert( !Commander<Protocol>::Null() );
- Assert( canDo == 0 || ((*Commander<Protocol>()).*canDo)() );
- ((*Commander<Protocol>()).*doIt)();
- }
- };
-
- #endif
-